using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.SupplyChain.Material;
using HengTong.Model;


namespace HengTong.ViewModel.SupplyChain.SysMeasureUnitGroupVms
{
    public partial class SysMeasureUnitGroupListVm : BaseListVm<SysMeasureUnitGroupView, SysMeasureUnitGroupSearcher>
    {

        protected override IEnumerable<IGridColumn<SysMeasureUnitGroupView>> InitGridHeader()
        {
            return new List<GridColumn<SysMeasureUnitGroupView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.Level),
                this.MakeGridHeader(x => x.ErpId),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.State),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeader(x => x.UpdateTime),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeader(x => x.CreateBy),
                this.MakeGridHeader(x => x.UpdateBy),
                this.MakeGridHeader(x => x.ParentName),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysMeasureUnitGroupView> GetSearchQuery()
        {
            var query = DC.Set<SysMeasureUnitGroup>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.ErpId, x=>x.ErpId)
                .CheckEqual(Searcher.State, x=>x.State)
                .CheckEqual(Searcher.ParentId, x=>x.ParentId)
                .Select(x => new SysMeasureUnitGroupView
                {
				    ID = x.ID,
                    Name = x.Name,
                    Code = x.Code,
                    Level = x.Level,
                    ErpId = x.ErpId,
                    Description = x.Description,
                    State = x.State,
                    CreateTime = x.CreateTime,
                    UpdateTime = x.UpdateTime,
                    Remark = x.Remark,
                    CreateBy = x.CreateBy,
                    UpdateBy = x.UpdateBy,
                    ParentName = x.Parent.Name,
                })
                .OrderBy(x => x.Code);
            return query;
        }
    }

    public class SysMeasureUnitGroupView : SysMeasureUnitGroup{
        [Display(Name = "名称")]
        public String ParentName { get; set; }

    }
}
